<?php

/**
 * This is the model class for table "xman_milestone".
 *
 * The followings are the available columns in table 'xman_milestone':
 * @property integer $milestone_id
 * @property string $milestone_due_date
 * @property string $milestone_completed_date
 * @property integer $milestone_notify
 * @property integer $milestone_reminder
 * @property integer $milestone_schedule_id
 *
 * The followings are the available model relations:
 * @property MilestoneUser[] $milestoneUsers
 */
class Milestone extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Milestone the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_milestone';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('milestone_schedule_id', 'required'),
			array('milestone_notify, milestone_reminder, milestone_schedule_id', 'numerical', 'integerOnly'=>true),
			array('milestone_due_date, milestone_completed_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('milestone_id, milestone_due_date, milestone_completed_date, milestone_notify, milestone_reminder, milestone_schedule_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'milestoneUsers' => array(self::HAS_MANY, 'MilestoneUser', 'milestone_user_milestone_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'milestone_id' => 'Milestone',
			'milestone_due_date' => 'Milestone Due Date',
			'milestone_completed_date' => 'Milestone Completed Date',
			'milestone_notify' => 'Milestone Notify',
			'milestone_reminder' => 'Milestone Reminder',
			'milestone_schedule_id' => 'Milestone Schedule',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('milestone_id',$this->milestone_id);
		$criteria->compare('milestone_due_date',$this->milestone_due_date,true);
		$criteria->compare('milestone_completed_date',$this->milestone_completed_date,true);
		$criteria->compare('milestone_notify',$this->milestone_notify);
		$criteria->compare('milestone_reminder',$this->milestone_reminder);
		$criteria->compare('milestone_schedule_id',$this->milestone_schedule_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
		/**
         * Get list of message people asscocative with project
         */
        public function getListUser($pid) {
        	$projectUsers = ProjectUser::model()->findAllByAttributes(array("project_user_project_id"=>$pid));
        	
        	$list = array();
        	foreach ($projectUsers as $projectUser) {
        		$list[$projectUser->project_user_user_id] = $projectUser->projectUserUser->user_name;
        	}
        	return $list;
        }
}